package com.grasp.activity.set;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.ExpandableListView;

import cc.wulian.ihome.wan.NetSDK;

import com.grasp.activity.R;
import com.grasp.base.ActionBar;
import com.grasp.base.ActionBarOnClick;
import com.grasp.base.BaseActivity;
import com.grasp.base.Logger;

/**
 * 设备管理
 */
public class DevicesManageActivity extends BaseActivity {

	private ExpandableListView mExpandableListView;
	private Button getDeviceListBtn;
	private ProgressDialog dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.set_devices_manage_layout);
		mExpandableListView = (ExpandableListView) findViewById(R.id.device_manage_listview);
		getDeviceListBtn = (Button) findViewById(R.id.get_device_list_btn);
		initActionBar();
	}

	private void initActionBar() {
		ActionBar mActionBar = (ActionBar) findViewById(R.id.device_manage_actionbar);
		mActionBar.setLeftBtnText(R.string.action_back);
		mActionBar.setRightBtnBackground(R.drawable.actionbar_sure_btn_bg);
		mActionBar.setActionBarOnClickListener(new ActionBarOnClick() {

			@Override
			public void rightBtnOnClick() {
			}

			@Override
			public void leftBtnOnClick() {
				finish();
			}
		});
	}

	private void showDialog() {
		if (null == dialog)
			dialog = new ProgressDialog(this);
		dialog.setMessage("正在获取设备列表");
		dialog.setIndeterminate(true);
		dialog.setCancelable(true);
		if (!dialog.isShowing())
			dialog.show();
	}

	public void getDeviceList(View v) {
		showDialog();
		new Thread() {
			public void run() {
				System.out.println("===>isValid:" + NetSDK.isValid());
				System.out.println("===>isConnected:" + NetSDK.isConnected());
				System.out.println("===>getGatewayID(): "+getGatewayID());
				NetSDK.sendRefreshDevListMsg(getGatewayID(), null);
			};
		}.start();
	}

	@Override
	public boolean handleMessage(Message msg) {
		Logger.d(getClass().getName() + "===>handleMessage_what:"+msg.what);
		if (null != dialog && dialog.isShowing()) {
			dialog.dismiss();
		}

		return false;
	}

}
